home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / stk-3.0 / stk-3 / blt-for-STk-3.0 / blt-1.9 / src / bltGrPS.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-01  |  9.3 KB  |  263 lines

  1. /*
  2.  * bltGrPS.h --
  3.  *
  4.  * Copyright 1993-1994 by AT&T Bell Laboratories.
  5.  * Permission to use, copy, modify, and distribute this software
  6.  * and its documentation for any purpose and without fee is hereby
  7.  * granted, provided that the above copyright notice appear in all
  8.  * copies and that both that the copyright notice and warranty
  9.  * disclaimer appear in supporting documentation, and that the
  10.  * names of AT&T Bell Laboratories any of their entities not be used
  11.  * in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * AT&T disclaims all warranties with regard to this software, including
  15.  * all implied warranties of merchantability and fitness.  In no event
  16.  * shall AT&T be liable for any special, indirect or consequential
  17.  * damages or any damages whatsoever resulting from loss of use, data
  18.  * or profits, whether in an action of contract, negligence or other
  19.  * tortuous action, arising out of or in connection with the use or
  20.  * performance of this software.
  21.  *
  22.  */
  23.  
  24. static char postScriptDefinitions[] =
  25. {
  26.     "\n\n\
  27. 200 dict begin\n\n\
  28. /BgColorProc 0 def    % Background color procedure (for symbols)\n\
  29. /BorderProc 0 def    % Border outline procedure (for symbols)\n\
  30. /StippleProc 0 def    % Stipple procedure (for bar segments)\n\
  31. /DashesProc 0 def    % Dashes procedure (for line segments)\n\n\
  32. \n\
  33. /encoding {ISOLatin1Encoding} def\n\
  34. systemdict /encodefont known {\n\
  35.     /realsetfont /setfont load def\n\
  36.     /setfont { encoding encodefont realsetfont } def\n\
  37. } if\n\n\
  38. /Stroke { gsave stroke grestore } def\n\n\
  39. /Fill { gsave fill grestore } def\n\n\
  40. /SetFont {     % Stack: pointSize fontName\n\
  41.     findfont exch scalefont setfont\n\
  42. } def\n\n\
  43. /SetDashes {        % Stack: numDashes\n\
  44.     dup 0 eq { pop [] 0 setdash } { 1 array astore 0 setdash } ifelse\n\
  45. } def\n\n\
  46. /Box {            % Stack: x y width height\n\
  47.     newpath\n\
  48.         exch 4 2 roll moveto\n\
  49.         dup 0 rlineto\n\
  50.         exch 0 exch rlineto\n\
  51.         neg 0 rlineto\n\
  52.     closepath\n\
  53. } def\n\n\
  54. /SetFgColor {        % Stack: red green blue\n\
  55.     CL 0 eq { pop pop pop 0 0 0 } if\n\
  56.     setrgbcolor\n\
  57.     CL 1 eq { currentgray setgray } if\n\
  58. } def\n\n\
  59. /SetBgColor {        % Stack: red green blue\n\
  60.     CL 0 eq { pop pop pop 1 1 1 } if\n\
  61.     setrgbcolor\n\
  62.     CL 1 eq { currentgray setgray } if\n\
  63. } def\n\n\
  64. % The next two definitions are taken from \"$tk_library/prolog.ps\"\n\n\
  65. % desiredSize EvenPixels closestSize\n\
  66. %\n\
  67. % The procedure below is used for stippling.  Given the optimal size\n\
  68. % of a dot in a stipple pattern in the current user coordinate system,\n\
  69. % compute the closest size that is an exact multiple of the device's\n\
  70. % pixel size.  This allows stipple patterns to be displayed without\n\
  71. % aliasing effects.\n\n\
  72. /EvenPixels {\n\
  73.     % Compute exact number of device pixels per stipple dot.\n\
  74.     dup 0 matrix currentmatrix dtransform\n\
  75.     dup mul exch dup mul add sqrt\n\n\
  76.     % Round to an integer, make sure the number is at least 1, and compute\n\
  77.     % user coord distance corresponding to this.\n\
  78.     dup round dup 1 lt {pop 1} if\n\
  79.     exch div mul\n\
  80. } bind def\n\n\
  81. % width height string filled StippleFill --\n\
  82. %\n\
  83. % Given a path and other graphics information already set up, this\n\
  84. % procedure will fill the current path in a stippled fashion.  \"String\"\n\
  85. % contains a proper image description of the stipple pattern and\n\
  86. % \"width\" and \"height\" give its dimensions.  If \"filled\" is true then\n\
  87. % it means that the area to be stippled is gotten by filling the\n\
  88. % current path (e.g. the interior of a polygon); if it's false, the\n\
  89. % area is gotten by stroking the current path (e.g. a wide line).\n\
  90. % Each stipple dot is assumed to be about one unit across in the\n\
  91. % current user coordinate system.\n\n\
  92. /StippleFill {\n\
  93.     % Turn the path into a clip region that we can then cover with\n\
  94.     % lots of images corresponding to the stipple pattern.  Warning:\n\
  95.     % some Postscript interpreters get errors during strokepath for\n\
  96.     % dashed lines.  If this happens, turn off dashes and try again.\n\n\
  97.     gsave\n\
  98.     {eoclip}\n\
  99.     {{strokepath} stopped {grestore gsave [] 0 setdash strokepath} if clip}\n\
  100.     ifelse\n\n\
  101.     % Change the scaling so that one user unit in user coordinates\n\
  102.     % corresponds to the size of one stipple dot.\n\
  103.     1 EvenPixels dup scale\n\n\
  104.     % Compute the bounding box occupied by the path (which is now\n\
  105.     % the clipping region), and round the lower coordinates down\n\
  106.     % to the nearest starting point for the stipple pattern.\n\n\
  107.     pathbbox\n\
  108.     4 2 roll\n\
  109.     5 index div cvi 5 index mul 4 1 roll\n\
  110.     6 index div cvi 6 index mul 3 2 roll\n\n\
  111.     % Stack now: width height string y1 y2 x1 x2\n\
  112.     % Below is a doubly-nested for loop to iterate across this area\n\
  113.     % in units of the stipple pattern size, going up columns then\n\
  114.     % across rows, blasting out a stipple-pattern-sized rectangle at\n\
  115.     % each position\n\n\
  116.     6 index exch {\n\
  117.     2 index 5 index 3 index {\n\
  118.         % Stack now: width height string y1 y2 x y\n\n\
  119.         gsave\n\
  120.         1 index exch translate\n\
  121.         5 index 5 index true matrix {3 index} imagemask\n\
  122.         grestore\n\
  123.     } for\n\
  124.     pop\n\
  125.     } for\n\
  126.     pop pop pop pop pop\n\
  127.     grestore\n\
  128.     newpath\n\
  129. } bind def\n\n\
  130. /DrawSegment {    % Stack: x1 y1 x2 y2\n\
  131.     newpath 4 2 roll moveto lineto stroke\n\
  132. } def\n\n\
  133. /DrawText {        % Stack: ?bgColorProc? boolean centerX centerY\n\
  134.             %      strWidth strHeight baseline theta str\n\
  135.     gsave\n\
  136.     7 -2 roll translate    % Translate to center of bounding box\n\
  137.     exch neg rotate        % Rotate by theta\n\
  138.     exch 4 2 roll\n\
  139.     2 copy 2 copy 2 copy\n\n\
  140.     % If needed, draw the background area, setting the bg color\n\n\
  141.     -0.5 mul exch -0.5 mul exch 4 -2 roll Box\n\
  142.         7 -1 roll { gsave 7 -1 roll exec fill grestore } if\n\n\
  143.     % Move to the text string starting position\n\n\
  144.     -.5  mul 5 -1 roll add exch -.5 mul exch moveto\n\
  145.     pop exch dup dup 4 2 roll\n\n\
  146.         % Adjust character widths to get desired overall string width\n\
  147.         % adjust X = (desired width - real width) / #chars\n\n\
  148.      stringwidth pop sub exch length div 0 3 -1 roll\n\n\
  149.     % Flip back the scale so that the string is not drawn in reverse\n\n\
  150.     1 -1 scale\n\
  151.     ashow\n\
  152.     grestore\n\
  153. } def\n\n\
  154. /DrawBitmap {        % Stack: ?bgColorProc? boolean centerX centerY\n\
  155.             %     width height theta imageStr\n\
  156.     gsave\n\
  157.     6 -2 roll translate    % Translate to center of bounding box\n\
  158.     4 1 roll neg rotate    % Rotate by theta\n\n\
  159.     % Find upperleft corner of bounding box\n\n\
  160.     2 copy -.5 mul exch -.5 mul exch translate\n\
  161.     2 copy scale        % Make pixel unit scale\n\
  162.         newpath\n\
  163.             0 0 moveto 0 1 lineto 1 1 lineto 1 0 lineto\n\
  164.         closepath\n\n\
  165.     % Fill rectangle with background color\n\n\
  166.     4 -1 roll { gsave 4 -1 roll exec fill grestore } if\n\n\
  167.     % Paint the image string into the unit rectangle\n\n\
  168.     2 copy true 3 -1 roll 0 0 5 -1 roll 0 0 6 array astore 5 -1 roll\n\
  169.         imagemask\n\
  170.     grestore\n\
  171. }def\n\n\
  172. % Symbols:\n\n\
  173. % Skinny-cross\n\
  174. /Sc {            % Stack: x y symbolSize\n\
  175.     gsave\n\
  176.     3 -2 roll translate 45 rotate\n\
  177.     0 0 3 -1 roll Sp\n\
  178.     grestore\n\
  179. } def\n\n\
  180. % Skinny-plus\n\
  181. /Sp {            % Stack: x y symbolSize\n\
  182.     gsave\n\
  183.     3 -2 roll translate\n\
  184.     2 idiv      % Stack: radius\n\
  185.     dup 2 copy    % Stack: radius radius radius radius\n\
  186.     newpath neg 0 moveto 0 lineto\n\
  187.     gsave BgColorProc fill grestore stroke\n\
  188.     newpath neg 0 exch moveto 0 exch lineto\n\
  189.     gsave BgColorProc fill grestore stroke\n\
  190.     grestore\n\
  191. } def\n\n\
  192. % Cross\n\
  193. /Cr {            % Stack: x y symbolSize\n\
  194.     gsave\n\
  195.     3 -2 roll translate 45 rotate\n\
  196.     0 0 3 -1 roll Pl\n\
  197.     grestore\n\
  198. } def\n\n\
  199. % Plus\n\
  200. /Pl {            % Stack: x y symbolSize\n\
  201.     gsave\n\
  202.     3 -2 roll translate\n\
  203.     dup 2 idiv      % Stack: size radius\n\
  204.     exch 6 idiv     % Stack: radius delta\n\n\
  205.     %\n\
  206.     %          2   3    The plus/cross symbol is a\n\
  207.     %            closed polygon of 12 points.\n\
  208.     %      0   1   4    5    The diagram to the left\n\
  209.     %           x,y        represents the positions of\n\
  210.     %     11  10   7    6    the points which are computed\n\
  211.     %            below.\n\
  212.     %          9   8\n\
  213.     %\n\n\
  214.     newpath\n\
  215.         2 copy exch neg exch neg moveto dup neg dup lineto\n\
  216.         2 copy neg exch neg lineto 2 copy exch neg lineto\n\
  217.         dup dup neg lineto 2 copy neg lineto 2 copy lineto\n\
  218.         dup dup lineto 2 copy exch lineto 2 copy neg exch lineto\n\
  219.         dup dup neg exch lineto exch neg exch lineto\n\
  220.     closepath\n\
  221.     Fill BorderProc\n\
  222.     grestore\n\
  223. } def\n\n\
  224. % Circle\n\
  225. /Ci {            % Stack: x y symbolSize\n\
  226.     3 copy pop\n\
  227.     moveto newpath\n\
  228.         2 div 0 360 arc\n\
  229.     closepath Fill BorderProc\n\
  230. } def\n\n\
  231. % Square\n\
  232. /Sq {            % Stack: x y symbolSize\n\
  233.     dup dup 2 div dup\n\
  234.     6 -1 roll exch sub exch\n\
  235.     5 -1 roll exch sub 4 -2 roll Box\n\
  236.     Fill BorderProc\n\
  237. } def\n\n\
  238. % Line\n\
  239. /Li {            % Stack: x y symbolSize\n\
  240.     3 1 roll exch 3 -1 roll 2 div 3 copy\n\
  241.     newpath\n\
  242.         sub exch moveto add exch lineto\n\
  243.     stroke\n\
  244. } def\n\n\
  245. % Diamond\n\
  246. /Di {            % Stack: x y symbolSize\n\
  247.     gsave\n\
  248.     3 1 roll translate 45 rotate 0 0 3 -1 roll Sq\n\
  249.     grestore\n\
  250. } def\n\n\n\
  251. %%BeginSetup\n\
  252. gsave            % Save the graphics state\n\n\
  253. % Default line style parameters\n\n\
  254. 1 setlinewidth        % width\n\
  255. 1 setlinejoin        % join\n\
  256. 0 setlinecap        % cap\n\
  257. 0 SetDashes        % dashes\n\n\
  258. % Adjust coordinate system to use X11 coordinates\n\n\
  259. 0 792 translate\n\
  260. 1 -1 scale\n\n\
  261. % User defined page layout\n\n"
  262. };
  263.